<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      v-model="form"
      :data="data"
      :page.sync="page"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menu" slot-scope="{ row }">
        <el-button type="text" size="small" icon="el-icon-view" @click="viewCheck(row, 'view')">详情</el-button>
        <el-button type="text" size="small" icon="el-icon-edit" v-if="permission.openingInspectionRecords_check && row.status == 3" @click="viewCheck(row, 'edit')"
          >检查</el-button
        >
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val)"></user-table-config>
      </template>
      <template slot="menuLeft">
        <el-button type="primary" size="small" icon="el-icon-plus" v-if="permission.openingInspectionRecords_add" @click="addConfig()">新增开线确认</el-button>
        <el-button type="warning" size="small" icon="el-icon-download" v-if="permission.openingInspectionRecords_export" @click="handleExport">导出</el-button>
      </template>
    </avue-crud>
    <el-dialog :title="dialogTitle" append-to-body :visible.sync="showDialog" @close="closeDialog" :fullscreen="true">
      <div class="groups">
        <div class="titleIcon">
          <i class="el-icon-vertical-bar avue-group__icon"></i>
          <h4>基本信息</h4>
        </div>
      </div>
      <avue-form ref="basicInfoForm" v-show="showDialog" v-model="basicInfoForm" :option="basicInfoOption">
        <template slot="attachments">
          <div v-if="dialogTitle != '查看'">
            <el-upload
              class="upload-demo"
              action="/api/blade-resource/oss/endpoint/put-file-attach"
              list-type="picture-card"
              accept=".png,.jpeg,.jpg"
              :on-preview="handlePreview"
              :headers="headersObj"
              :before-upload="pictureUploadBefore"
              :on-success="pictureUploadSuccess"
              :limit="1"
              :file-list="pictureList"
              :on-remove="pictureRemoveFile"
            >
              <i class="el-icon-plus"></i>
              <div slot="tip" class="el-upload__tip">只能上传png/jpeg/jpg文件</div>
            </el-upload>
          </div>
          <div v-if="dialogTitle === '查看'">
            <div v-for="(item, index) in pictureList" :key="index">
              <el-image style="width: 100px; height: 100px; padding-right: 10px; display: block" :src="item.url" @click="openPreview(0, item.url)"></el-image>
              <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(item.url)">下载</el-button>
            </div>
          </div>
        </template>
      </avue-form>

      <div class="groups">
        <div class="titleIcon">
          <i class="el-icon-vertical-bar avue-group__icon"></i>
          <h4>检查结果</h4>
        </div>
      </div>
      <avue-crud v-if="showDialog" :option="checkRecordOption" :data="checkRecordData"></avue-crud>
      <el-row style="line-height: 40px" v-if="result != ''">
        <el-col :span="2">综合结果判定：</el-col>
        <el-col :span="22">
          <el-radio-group v-model="result" :disabled="true">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="3">让步通过</el-radio>
            <el-radio :label="2">不通过</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
      <div class="groups">
        <div class="titleIcon">
          <i class="el-icon-vertical-bar avue-group__icon"></i>
          <h4>历史检查结果</h4>
        </div>
      </div>
      <avue-crud v-if="showDialog" :option="historyRecordOption" :data="historyRecordData">
        <template slot="menu" slot-scope="{ row }">
          <el-button type="text" size="small" icon="el-icon-view" @click="historyRecordDetail(row)">详情</el-button>
        </template>
      </avue-crud>
      <div slot="footer">
        <el-button size="small" type="primary" v-if="dialogTitle != '查看'" @click="handleCheck()"><i class="el-icon-circle-plus-outline"></i><span>检 查</span></el-button>
        <el-button size="small" type="primary" v-if="dialogTitle != '查看'" @click="handleSubmit()"><i class="el-icon-circle-plus-outline"></i><span>提 交</span></el-button>
        <el-button size="small" @click="showDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </div>
    </el-dialog>
    <el-dialog title="历史检查结果明细" append-to-body :visible.sync="showHistoryRecordDetailDialog">
      <el-row style="line-height: 40px">
        <el-col :span="3">综合结果判定：</el-col>
        <el-col :span="21">
          <el-radio-group v-model="historyRecordResult" :disabled="true">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="3">让步通过</el-radio>
            <el-radio :label="2">不通过</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
      <avue-crud v-if="showHistoryRecordDetailDialog" :option="historyRecordDetailOption" :data="historyRecordDetailData"></avue-crud>
      <div slot="footer">
        <el-button size="small" @click="showHistoryRecordDetailDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </div>
    </el-dialog>
    <export-comp ref="exportComp" page-api-url="mes-product/openingcheck/result/page" :option="option" :page="page" :query="query" file-name="开线检查记录"> </export-comp>
    <!--公用模态弹框-->
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows"></common-modal-template>
  </basic-container>
</template>

<script>
import { getList, getDetail, getSectionByLineId, getCheckResult, check, submit } from '@/api/product/openingInspectionRecords';
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config/index.vue';
import userConfig from '@/mixins/userConfig';
import website from '@/config/website';
import { Base64 } from 'js-base64';
import { getToken } from '@/util/auth';
import { getQmsTemplateFile } from '@/api/resource/attach';
import commonModalTemplate from '@/components/common-modal-template/common-modal-template';
import exportComp from '@/components/export-comp';
export default {
  components: {
    userTableConfig,
    commonModalTemplate,
    exportComp
  },
  mixins: [userConfig()],
  data() {
    return {
      fullscreenDialog: false, //dialog是否全屏
      form: {},
      model: {},
      loading: true,
      downLoadVisible: false,
      templateList: [],
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      data: [],
      selectData: [],
      code: '00',
      searchLabelWidth: 100,
      checkIqc: true,
      option: {
        height: 'calc(100vh - 482px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        border: true,
        index: true,
        indexLabel: '序号',
        viewBtn: false,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        selection: true,
        dialogClickModal: false,
        labelWidth: 120,
        searchMenuSpan: 12,
        searchMenuPosition: 'right',
        searchLabelWidth: 105,
        menuWidth: 250,
        columnBtn: false,
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true,
            searchOrder: 3
          },
          {
            label: '产线',
            prop: 'lineName',
            search: true,
            searchOrder: 4
          },
          {
            label: '工段',
            prop: 'sectionName'
          },
          {
            label: '产品编码',
            prop: 'partNo',
            search: true,
            searchOrder: 1
          },
          {
            label: '产品名称',
            prop: 'partName',
            search: true,
            searchOrder: 2
          },
          {
            label: '检查时机',
            prop: 'checkMoment',
            search: true,
            searchOrder: 5,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=inspection_timing',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '检查状态',
            prop: 'status',
            type: 'select',
            dicData: [
              { label: '已完成', value: 1 },
              { label: '已失效', value: 2 },
              { label: '检查中', value: 3 }
            ]
          },
          {
            label: '综合判断结果',
            prop: 'result',
            search: true,
            searchOrder: 6,
            type: 'select',
            dicData: [
              { label: '通过', value: 1 },
              { label: '未通过', value: 2 },
              { label: '让步通过', value: 3 }
            ]
          },
          {
            label: '备注',
            prop: 'remark'
          },
          {
            label: '检查人',
            prop: 'updateUserName'
          },
          {
            label: '检查时间',
            prop: 'updateTime'
          }
        ]
      },
      tableOption: {},
      showDialog: false,
      dialogTitle: '新增开线检查',
      basicInfoForm: {},
      basicInfoOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '检查时机',
            prop: 'checkMoment',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=inspection_timing',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            rules: [
              {
                required: true,
                message: '请输入检查时机',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '产线',
            prop: 'lineName',
            disabled: true,
            type: 'search',
            appendClick: () => {
              if (this.dialogTitle === '新增开线检查') {
                this.openProductLineCommonModal();
              }
            },
            rules: [
              {
                required: true,
                message: '请选择产线',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工单号',
            prop: 'workOrderNo',
            disabled: true,
            type: 'search',
            appendClick: () => {
              if (this.dialogTitle === '新增开线检查') {
                this.openWorkOrderCommonModal();
              }
            },
            rules: [
              {
                required: true,
                message: '请选择工单号',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工段',
            prop: 'sectionName',
            disabled: true
          },
          {
            label: '产品名称',
            prop: 'partName',
            disabled: true
          },
          {
            label: '产品编码',
            prop: 'partNo',
            disabled: true
          },
          {
            label: '产品型号',
            prop: 'partModel',
            disabled: true
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea',
            minRows: 3
          },
          {
            label: '上传附件',
            prop: 'attachments',
            type: 'upload',
            span: 16,
            loadText: '图片上传中，请稍等',
            propsHttp: {
              url: 'link',
              name: 'attachId',
              res: 'data'
            },
            listType: 'picture-card',
            accept: 'image/png, image/jpeg, image/jpg',
            tip: '只能上传png/jpeg/jpg文件',
            action: '/api/blade-resource/oss/endpoint/put-file-attach'
          }
        ]
      },
      pictureList: [],
      configId: '',
      checkRecordData: [],
      checkRecordOption: {
        height: '300',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: true,
        menu: true,
        cellBtn: false,
        refreshBtn: false,
        columnBtn: false,
        column: [
          {
            label: '检验项类型',
            prop: 'type',
            type: 'select',
            dicData: [
              { label: '物料', value: 'MATERIAL' },
              { label: '设备', value: 'EQUIPMENT' }
            ]
          },
          {
            label: '检查内容',
            prop: 'description'
          },
          {
            label: '检验结果',
            prop: 'result',
            type: 'select',
            dicData: [
              { label: '', value: '' },
              { label: 'OK', value: 1 },
              { label: 'NG', value: 2 },
              { label: 'OK', value: 3 }
            ]
          },
          {
            label: '异常原因',
            prop: 'exception'
          },
          {
            label: '接受异常',
            prop: 'acceptException',
            type: 'switch',
            dicData: [
              { label: '否', value: false },
              { label: '是', value: true }
            ],
            cell: true,
            change: (val) => {
              console.log(val);
              this.checkRecordData[val.index].result = val.value ? 3 : 2;
              let ngNum = 0;
              this._forEach(this.checkRecordData, (item) => {
                if (item.result == 2) {
                  ngNum++;
                }
              });
              if (ngNum === 0) {
                this.result = 3;
              } else {
                this.result = 2;
              }
            }
          },
          {
            label: '备注',
            prop: 'remark',
            cell: true
          }
        ]
      },
      result: '',
      historyRecordData: [],
      historyRecordOption: {
        height: '300',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: false,
        menu: true,
        refreshBtn: false,
        columnBtn: false,
        column: [
          {
            label: '综合结果判定',
            prop: 'result',
            type: 'select',
            dicData: [
              { label: '通过', value: 1 },
              { label: '未通过', value: 2 },
              { label: '让步通过', value: 3 }
            ]
          },
          {
            label: '检查时间',
            prop: 'updateTime'
          },
          {
            label: '检查人',
            prop: 'updateUserName'
          }
        ]
      },
      showHistoryRecordDetailDialog: false,
      historyRecordDetailData: [],
      historyRecordDetailOption: {
        height: '300',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: false,
        menu: false,
        cellBtn: false,
        refreshBtn: false,
        columnBtn: false,
        column: [
          {
            label: '检验项类型',
            prop: 'type',
            type: 'select',
            dicData: [
              { label: '物料', value: 'MATERIAL' },
              { label: '设备', value: 'EQUIPMENT' }
            ]
          },
          {
            label: '检查内容',
            prop: 'description'
          },
          {
            label: '检验结果',
            prop: 'result',
            type: 'select',
            dicData: [
              { label: 'OK', value: 1 },
              { label: 'NG', value: 2 },
              { label: 'OK', value: 3 }
            ]
          },
          {
            label: '异常原因',
            prop: 'exception'
          },
          {
            label: '接受异常',
            prop: 'acceptException',
            type: 'switch',
            dicData: [
              { label: '否', value: false },
              { label: '是', value: true }
            ]
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      },
      historyRecordResult: ''
    };
  },
  computed: {
    ...mapGetters(['permission']),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },
    headersObj() {
      let header = { Authorization: `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}` };
      header['Blade-Auth'] = 'bearer ' + getToken();
      return header;
    }
  },
  watch: {
    'basicInfoForm.checkMoment'(val) {
      if (this.dialogTitle === '编辑' && val && this.basicInfoForm.lineId && this.basicInfoForm.workOrderNo) {
        this.queryCheckResult();
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  methods: {
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data.records;
        this._forEach(this.data, (item) => {
          item.checkMoment = String(item.checkMoment);
        });
        this.page.total = data.total;
        this.loading = false;
      });
    },
    addConfig() {
      this.showDialog = true;
      this.dialogTitle = '新增开线检查';
      this.$nextTick(() => {
        this.$refs.basicInfoForm.allDisabled = false;
      });
      this.basicInfoForm.attachments = {};
      //   this.workSectionRecordOption.menu = true;
    },
    openProductLineCommonModal() {
      this.modalName = 'lineModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择产线信息（双击进行选择）',
        url: '/api/mes-product/productionline/page',
        isPage: true,
        rowSelectionType: 'single',
        menu: false,
        editBtn: false,
        menuWidth: 100,
        columnDefs: [
          {
            label: '产线名称',
            prop: 'name',
            search: true
          },
          {
            label: '产线编码',
            prop: 'code',
            search: true
          }
        ]
      };
    },
    openWorkOrderCommonModal() {
      this.modalName = 'workOrderModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择工单号（双击进行选择）',
        url: '/api/mes-product/work-order/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '生产订单',
            prop: 'productionOrderNo',
            search: true
          },
          {
            label: '生产工单',
            prop: 'orderNo',
            search: true
          },
          {
            label: '工单类型',
            prop: 'orderType',
            type: 'select'
          },
          {
            label: '工单数量',
            prop: 'planQuantity'
          },
          {
            label: '产品编码',
            prop: 'partNo'
          },
          {
            label: '产品名称',
            prop: 'partName'
          },
          {
            label: 'BOM版本',
            prop: 'bomVersion'
          },
          {
            label: '派工产线',
            prop: 'productionLineName'
          },
          {
            label: '计划开始时间',
            prop: 'planStartDate'
          },
          {
            label: '计划结束时间',
            prop: 'planEndDate'
          },
          {
            label: '制定人',
            prop: 'creatorName'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            dicData: [
              {
                label: '待排程',
                value: 1
              },
              {
                label: '待生产',
                value: 2
              },
              {
                label: '生产中',
                value: 3
              },
              {
                label: '完工',
                value: 4
              },
              {
                label: '锁定',
                value: 5
              },
              {
                label: '强制完工',
                value: 6
              }
            ]
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      };
    },
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'lineModal':
          this.basicInfoForm.lineId = this._get(rowData, 'id', '');
          this.basicInfoForm.lineCode = this._get(rowData, 'code', '');
          this.basicInfoForm.lineName = this._get(rowData, 'name', '');
          getSectionByLineId({ lineId: this.basicInfoForm.lineId }).then((res) => {
            if (res.data.data != null) {
              this.basicInfoForm.sectionId = this._get(res, 'data.data.sectionId', '');
              this.basicInfoForm.sectionCode = this._get(res, 'data.data.sectionCode', '');
              this.basicInfoForm.sectionName = this._get(res, 'data.data.sectionName', '');
              if (this.basicInfoForm.checkMoment && this.basicInfoForm.lineId && this.basicInfoForm.workOrderNo) {
                this.queryCheckResult();
              }
            } else {
              this.$message.error('未查询到工段，请前往工段定义配置！');
              this.basicInfoForm.sectionId = '';
              this.basicInfoForm.sectionCode = '';
              this.basicInfoForm.sectionName = '';
            }
          });
          break;
        case 'workOrderModal':
          this.basicInfoForm.workOrderId = this._get(rowData, 'id', '');
          this.basicInfoForm.workOrderNo = this._get(rowData, 'orderNo', '');
          this.basicInfoForm.partNo = this._get(rowData, 'partNo', '');
          this.basicInfoForm.partName = this._get(rowData, 'partName', '');
          this.basicInfoForm.partModel = this._get(rowData, 'partModel', '');
          if (this.basicInfoForm.checkMoment && this.basicInfoForm.lineId && this.basicInfoForm.workOrderNo) {
            this.queryCheckResult();
          }
          break;
        default:
          break;
      }
    },
    queryCheckResult() {
      getCheckResult({
        checkMoment: this.basicInfoForm.checkMoment,
        lineId: this.basicInfoForm.lineId,
        workOrderId: this.basicInfoForm.workOrderId,
        sectionId: this.basicInfoForm.sectionId
      }).then(
        (res) => {
          this.configId = this._get(res, 'data.data.configId', '');
          this.basicInfoForm.id = this._get(res, 'data.data.id', '');
          if (this.dialogTitle != '新增开线检查') {
            this.basicInfoForm.lineCode = this._get(res, 'data.data.lineCode', '');
            this.basicInfoForm.sectionCode = this._get(res, 'data.data.sectionCode', '');
          }
          let data = this._get(res, 'data.data.configItems', []);
          this.checkRecordData = this._map(data, (item) => {
            return {
              type: item.type,
              code: item.code,
              description: item.description,
              result: item.result,
              exception: item.exception,
              acceptException: item.acceptException,
              remark: item.remark,
              $cellEdit: item.result != null && item.result != 1 ? true : false
            };
          });
          let okNum = 0;
          let ngNum = 0;
          this._forEach(this.checkRecordData, (item) => {
            if (item.result == 1) {
              okNum++;
            }
            if (item.result == 2) {
              ngNum++;
            }
          });
          if (okNum > 0 && ngNum === 0) {
            this.result = 1;
          } else if (okNum === 0 && ngNum > 0) {
            this.result = 2;
          }
        },
        (error) => {
          this.checkRecordData = [];
        }
      );
    },
    workSectionRecordDel(index) {
      this.workSectionRecordData.splice(index, 1);
    },
    handleSubmit() {
      if (this.result == 2) {
        this.$message.warning('请处理异常结果后提交！');
        return;
      }
      let params = {
        attachmentId: this.basicInfoForm.attachments.attachmentId ? this.basicInfoForm.attachments.attachmentId : null,
        checkMoment: this.basicInfoForm.checkMoment,
        configId: this.configId,
        id: this.basicInfoForm.id,
        lineId: this.basicInfoForm.lineId,
        lineCode: this.basicInfoForm.lineCode,
        lineName: this.basicInfoForm.lineName,
        remark: this.basicInfoForm.remark,
        result: this.result,
        sectionId: this.basicInfoForm.sectionId,
        sectionCode: this.basicInfoForm.sectionCode,
        sectionName: this.basicInfoForm.sectionName,
        workOrderId: this.basicInfoForm.workOrderId,
        workOrderNo: this.basicInfoForm.workOrderNo,
        configItems: this.checkRecordData
      };
      submit(params).then((res) => {
        this.$message.success(res.data.msg);
        this.showDialog = false;
        this.onLoad(this.page);
      });
    },
    closeDialog() {
      this.$refs.basicInfoForm.resetFields();
      this.basicInfoForm = {};
      this.pictureList = [];
      this.checkRecordData = [];
      this.result = '';
    },
    viewCheck(row, type) {
      this.showDialog = true;
      if (type === 'view') {
        this.dialogTitle = '查看';
        this.$nextTick(() => {
          this.$refs.basicInfoForm.allDisabled = true;
        });
      } else {
        this.dialogTitle = '编辑';
        this.$nextTick(() => {
          this.$refs.basicInfoForm.allDisabled = false;
        });
      }
      getDetail(row.id).then((res) => {
        this.basicInfoForm = this._get(res, 'data.data', {});
        console.log(this.basicInfoForm);
        this.basicInfoForm.checkMoment = String(this.basicInfoForm.checkMoment);
        this.pictureList = [];
        if (this.basicInfoForm.attachUrl != null) {
          this.pictureList.push({
            url: this.basicInfoForm.attachUrl,
            name: this.basicInfoForm.attachName
          });
        }
        this.basicInfoForm.attachments = {
          attachmentId: this.basicInfoForm.attachmentId,
          link: this.basicInfoForm.attachUrl,
          attachmentName: res.data.attachName
        };
        if (type === 'view') {
          this.checkRecordData = this.basicInfoForm.configItems;
        } else {
          this.queryCheckResult();
        }
        this.historyRecordData = this.basicInfoForm.historyRecordList;
        this.result = this.basicInfoForm.result;
      });
    },
    deleteConfig(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return remove([row.id]);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let ids = this.ids.split(',');
          return remove(ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.$refs.crud.toggleSelection();
        });
    },
    handleEnable(id) {
      enable(id)
        .then((res) => {
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.onLoad(this.page);
        })
        .catch((err) => {});
    },
    handleDisable(id) {
      enable(id)
        .then((res) => {
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.onLoad(this.page);
        })
        .catch((err) => {});
    },
    /**
     * 上传前方法
     */
    pictureUploadBefore(file) {
      console.log(file);
      if (file.name.split('.')[1] != 'png' && file.name.split('.')[1] != 'jpeg' && file.name.split('.')[1] != 'jpg') {
        this.$message({
          type: 'warning',
          message: '只能上传png/jpeg/jpg文件！'
        });
        return false;
      }
    },
    pictureUploadSuccess(res) {
      // this.addFailureRecordForm.attachments = res.data.link;
      this.basicInfoForm.attachments = {
        attachmentId: res.data.attachId,
        link: res.data.link,
        attachmentName: res.data.originalName
      };
    },
    handlePreview(file) {
      console.log(file);
      let url = this._get(file, 'response.data.link', '');
      this.$ImagePreview([{ url: url ? url : file.url }], 0, {
        closeOnClickModal: false
      });
    },
    pictureRemoveFile(file) {
      this.pictureList.splice(0, 1);
    },
    handleCheck() {
      this._forEach(this.checkRecordData, (item) => {
        delete item.acceptException;
      });
      let params = {
        attachmentId: this.basicInfoForm.attachments.attachmentId ? this.basicInfoForm.attachments.attachmentId : null,
        checkMoment: this.basicInfoForm.checkMoment,
        configId: this.configId,
        id: this.basicInfoForm.id,
        lineId: this.basicInfoForm.lineId,
        lineCode: this.basicInfoForm.lineCode,
        lineName: this.basicInfoForm.lineName,
        remark: this.basicInfoForm.remark,
        result: this.basicInfoForm.result,
        sectionId: this.basicInfoForm.sectionId,
        sectionCode: this.basicInfoForm.sectionCode,
        sectionName: this.basicInfoForm.sectionName,
        workOrderId: this.basicInfoForm.workOrderId,
        workOrderNo: this.basicInfoForm.workOrderNo,
        configItems: this.checkRecordData
      };
      check(params).then((res) => {
        this.$message.success(res.data.msg);
        this.queryCheckResult();
      });
    },
    historyRecordDetail(row) {
      this.showHistoryRecordDetailDialog = true;
      this.historyRecordResult = row.result;
      this.historyRecordDetailData = row.configItems;
    },
    handleDownload(link) {
      window.open(`${link}`);
    },
    openPreview(index = 0, link) {
      this.$ImagePreview([{ url: link }], index, {
        closeOnClickModal: false
      });
    },
    handleExport() {
      this.$refs.exportComp.visible = true;
    }
  }
};
</script>

<style scoped lang="scss">
$size: 16px;
.view-style {
  font-weight: bold;
  font-size: $size;
}
.iqc-placeholder {
  font-size: $size;
  color: #aaaaaa;
}
.iqcDialog {
  ::v-deep input[type='file'] {
    display: none !important;
  }
  ::v-deep .el-form-item__label {
    font-weight: bold;
    font-size: 16px;
  }
}
$BORDER-STYLE: 1px solid #f0f0f0 !important;
::v-deep .inspection-btn:hover {
  background-color: #dedede;
}
::v-deep .el-dialog__header {
  border-bottom: $BORDER-STYLE;
}

::v-deep .el-dialog__footer {
  border-top: $BORDER-STYLE;
}

.fill-screen-icon {
  color: #909399;
  font-size: 15px;
  float: right;
  padding-right: 25px;
  &:hover {
    color: #409eff;
  }
}

.group-title {
  border-bottom: 1px solid rgb(240, 240, 240) !important;
  font-size: 16px;
  font-weight: 500;
  height: 50px;
  line-height: 50px;
  color: rgba(0, 0, 0, 0.85);
  margin-bottom: 20px;
}
::v-deep .urgent-select-row {
  color: red;
}
.groups {
  margin: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #dedede;
  .titleIcon {
    display: flex;
    align-items: center;
  }
}
.aqlValueDialog {
  ::v-deep .el-form-item__content {
    line-height: 33px;
  }
}

.title-result {
  display: flex;
  justify-content: space-between;
  .title {
    display: flex;
    align-items: center;
  }
  .reslut-btn-group {
    margin-right: 8px;
  }
}
.download-box {
  .dowload-item {
    margin: 4px 8px;
    color: #007dff;
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none;
    &:hover {
      cursor: pointer;
    }
  }
}
::v-deep .el-dialog__body {
  .el-card__body {
    .avue-crud__menu {
      display: none;
    }
  }
}
</style>
